package com.sdut.material.controller;


import com.sdut.material.pojo.Production;
import com.sdut.material.pojo.Type;
import com.sdut.material.service.ITypeService;
import com.sdut.material.util.JSONResult;
import com.sdut.material.util.LayUITableResult;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yu
 * @since 2022-04-20
 */
@Controller
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private ITypeService typeService;
    @RequestMapping("/getTypeListPage")
    public String getProductionListPage() {
        return "type/type_list";
    }
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(Long page, Long limit) {
        return typeService.selectByPage(page,limit);
    }
    @RequestMapping("/getTypeInsertPage")
    public String getProductionInsertPage() {
        return "type/type_insert";
    }
    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Type type) {
        return typeService.insert(type);
    }
    @RequestMapping("/getTypeUpdatePage")
    public String getProductionUpdatePage() {
        return "type/type_update";
    }
    @RequestMapping("/selectById")
    @ResponseBody
    public JSONResult selectById(Integer typeId) {
        Type type = typeService.selectById(typeId);
        return JSONResult.ok(type);
    }
    @RequestMapping("/update")
    @ResponseBody
    public JSONResult updateType(Type type) {
        typeService.updateType(type);
        return JSONResult.ok("修改成功");
    }
    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer typeId) {
        typeService.deleteById(typeId);
        return JSONResult.ok("删除成功");
    }
    @RequestMapping("/deleteAll")
    @ResponseBody
    public JSONResult deleteAll(String ids) {
        String[] typeIds = ids.split(",");
        for (String id : typeIds) {
            typeService.deleteById(Integer.parseInt(id));
        }
        return JSONResult.ok("删除成功");
    }
    @RequestMapping("/selectAllTypes")
    @ResponseBody
    public JSONResult selectAllTypes() {
        return typeService.selectAllTypes();
    }
}

